using System;
using System.Collections.Generic;
using System.Windows;

namespace DeSleeper.Client.Installation
{
    /// <summary>
    /// Options that control the installation of the deSleeper Service.
    /// </summary>
    internal class InstallServiceOptions : Freezable
    {
        #region LocalAddress Dependency Property
        /// <summary>
        /// What is the URI the service should listen for requests?  In the form of http://localhost/whateverURIuserchooses.
        /// </summary>
        public string LocalAddress
        {
            get { return (string) GetValue(LocalAddressProperty); }
            set { SetValue(LocalAddressProperty, value); }
        }

        /// <summary>
        /// LocalAddress Dependency Property.
        /// </summary>
        public static readonly DependencyProperty LocalAddressProperty =
            DependencyProperty.Register(
                "LocalAddress",
                typeof (string),
                typeof (InstallServiceOptions));
        #endregion

        #region ShouldRegisterWithMesh Dependency Property
        /// <summary>
        /// Should the service register itself with a P2P Mesh?
        /// </summary>
        public bool ShouldRegisterWithMesh
        {
            get { return (bool) GetValue(ShouldRegisterWithMeshProperty); }
            set { SetValue(ShouldRegisterWithMeshProperty, value); }
        }

        /// <summary>
        /// ShouldRegisterWithMesh Dependency Property.
        /// </summary>
        public static readonly DependencyProperty ShouldRegisterWithMeshProperty =
            DependencyProperty.Register(
                "ShouldRegisterWithMesh",
                typeof (bool),
                typeof (InstallServiceOptions));
        #endregion
        #region MeshAddress Dependency Property
        /// <summary>
        /// The URI of the P2P mesh to connect to, if any.
        /// </summary>
        public string MeshAddress
        {
            get { return (string) GetValue(MeshAddressProperty); }
            set { SetValue(MeshAddressProperty, value); }
        }

        /// <summary>
        /// MeshAddress Dependency Property.
        /// </summary>
        public static readonly DependencyProperty MeshAddressProperty =
            DependencyProperty.Register(
                "MeshAddress",
                typeof (string),
                typeof (InstallServiceOptions));
        #endregion

        protected override Freezable CreateInstanceCore()
        {
            return new InstallServiceOptions();
        }

        public IEnumerable<string> GetArguments()
        {
            yield return String.Format("/LocalAddress={0}", LocalAddress);
            if (ShouldRegisterWithMesh)
                yield return String.Format("/PeerAddress={0}", MeshAddress);
        }
    }
}